/*
 *
 *
 *
 *
 */

package com.usefullc.user.domain;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.usefullc.system.entity.BaseEntity;
import com.usefullc.common.enums.UserGenderEnum;
import com.usefullc.common.enums.UserStatusEnum;
import com.usefullc.system.service.component.dict.DictField;
import com.usefullc.system.service.component.dict.EnumField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@JsonIgnoreProperties(value = {"roleList","delState","pwd","payPwd"})
@ApiModel("用户")
@Entity(name = "u_user")
@Table(indexes = {@Index(name = "user_account_index", columnList = "type,accountNo", unique = true),
//        @Index(name = "user_mobile_index", columnList = "type,areaCode,mobile", unique = true),
//        @Index(name = "user_email_index", columnList = "type,email", unique = true),
})
@Data
public class User extends BaseEntity {


    @ApiModelProperty(notes = "账号/用户名")
    @Column(length = 50, nullable = false)
    private String accountNo;

    @ApiModelProperty(notes = "密码")
    @Column(length = 50, nullable = false)
    private String pwd;

    @ApiModelProperty(notes = "昵称")
    @Column(length = 50, nullable = false)
    private String nickname;

    @ApiModelProperty(notes = "类型")
    @Column(length = 4, nullable = false)
    private Integer type;


    @EnumField(cls = UserStatusEnum.class)
    @ApiModelProperty(notes = "状态")
    @Column(length = 4, nullable = false)
    private Integer status;


    @ApiModelProperty(notes = "国家区号")
    @Column(length = 30)
    private String areaCode;

    @ApiModelProperty(notes = "微信")
    @Column(length = 30)
    private String wechat;

    @ApiModelProperty(notes = "手机")
    @Column(length = 30)
    private String mobile;

    @ApiModelProperty(notes = "邮件")
    @Column(length = 50)
    private String email;

    @EnumField(cls = UserGenderEnum.class)
    @ApiModelProperty(notes = "性别")
    @Column(length = 1)
    private Integer gender;

    @ApiModelProperty(notes = "生日")
    @Column(length = 20)
    private Date birthday;

    @ApiModelProperty(notes = "宣言")
    @Column(length = 200)
    private String message;

    @ApiModelProperty(notes = "头像")
    @Column(length = 200)
    private String avatar;


    @ApiModelProperty(notes = "描述")
    @Column(name = "[desc]", length = 1000)
    private String desc;

    @ApiModelProperty(notes = "支付密码")
    @Column(length = 50)
    private String payPwd;

    @ApiModelProperty(notes = "用户地址")
    @Column(length = 1000)
    private String address;


    @ApiModelProperty(notes = "用户姓名")
    @Column(length = 50)
    private String userName;

    @JSONField(serialize = false)
    @ApiModelProperty(notes = "角色")
    @ManyToMany(cascade = CascadeType.REFRESH)
    @JoinTable(name = "u_user_role", joinColumns = {
            @JoinColumn(name = "userId", referencedColumnName = "id")}, inverseJoinColumns = {
            @JoinColumn(name = "roleId", referencedColumnName = "id")})
    private List<Role> roleList;

//    @JSONField(serialize = false)
    @ApiModelProperty(notes = "部门")
    @ManyToOne(cascade = CascadeType.REFRESH)
    @JoinColumn(name="deptId")
    private Dept dept;

//    @JSONField(serialize = false)
    @ApiModelProperty(notes = "职位")
    @ManyToOne(cascade = CascadeType.REFRESH)
    @JoinColumn(name="positionId")
    private Position position;


    @DictField(value="career")
    @ApiModelProperty(notes = "职业")
    @Column(length = 50)
    private String career;


    @ApiModelProperty(notes = "邀请码")
    @Column(length = 50)
    private String inviteCode;

    @ApiModelProperty(notes = "别人的邀请码")
    @Column(length = 50)
    private String shareInviteCode;

    @Column(name="local",length = 16)
    private String local;


    @ApiModelProperty(notes = "第三方用户ID")
    @Column(length = 100)
    private String otherUserId;

    public User() {
    }


}
